$(function(){
	var childIds;
	var childBirthday;
	ym.ajax({
		url: "/userChild/getChildName",
		success: function (data) {
		   	if(data.res == 1){
		   		$('.baobao').html("");
               if(data.obj.length > 0){
					var html ="";
					for(var i=0;i<data.obj.length;i++){
						if(i == 0){
							html += '<option value="'+data.obj[i].birthday+','+data.obj[i].childId+'" selected>'+data.obj[i].childName+'</option>';
						}else{
							html += '<option value="'+data.obj[i].birthday+','+data.obj[i].childId+'">'+data.obj[i].childName+'</option>';
						}
		   			}
                    $('.baobao').append(html);
                    var child = $(".baobao option:selected").val();
					var ass = [];
					ass = child.split(",");
					childIds = ass[1];
					childBirthday = ass[0];
					console.log(childIds);
					console.log(childBirthday);
			        ones(childBirthday);
		   		}else{
		   			window.location.href = "vaccine1.html";
		   			console.log("没有宝宝(没有获取到当前用户宝宝的生日和id)");
				}
		   	}else{console.log("获取宝宝失败!")}
		}
	});
	
	$('.baobao').on('change',function(){
		$('.vaccinename').html("");
		$('.xgymxq').html("");
		$('.agePeriod').html("");
		var child = $(this).val();
		var ass = [];
		ass = child.split(",");
		childIds = ass[1];
		var childBirthday = ass[0];
		console.log(childBirthday);
		ones(childBirthday);
	})
	
	/*接种计划*/
	var arr4=[];
	function ones(childBirthday){
		arr4 =[];
		ym.ajax({
			url: "/vaccine/queryVaccineInoculationPlan",
			param:{ 
				childBirthday:childBirthday,
			},
			success: function (data) {
				console.log(data);
			   if(data.res == 1){
					$('.vaccinename').html("");
			   		var html = "";
			   		console.log(data);
			   		if(data.obj.length > 0){
			   			$('.ckxgym').removeClass('none');
			   			for(var i=0;i<data.obj.length;i++){
				   			var arr =[];
				   			var arr2 = [];
				   			var arr3 = [];
				   			var zhi = data.obj[0].vaccineTypeName.indexOf(',');
				   			if(zhi == -1){
				   				data.obj[i].vaccineTypeName  = data.obj[i].vaccineTypeName+",";
				   			}
				   			arr = data.obj[i].vaccineTypeName.split('/');
				   			if(i == 0){
				   				html = '<li class="actives">'+arr[0]+'</li>';
				   			}else{
				   				html = '<li>'+arr[0]+'</li>';
				   			}
				   			$('.agePeriod').append(html);
				   		}
				   		arr2 = data.obj[0].vaccineTypeName.split(',');
				   		arr4 =[];
			   			for(var j=0;j<arr2.length;j++){
			   				var htmls = "";
			   				arr3 = arr2[j].split("/");
			   				arr4.push(arr3[3]);
			   				htmls += '<div class="am-margin-top-sm zjyy_div am-padding-sm borbottoms">';
							    htmls += '<div class="am-block removefloat advice" onclick="window.location.href=\'vaccineXQ.html?vaccineId='+arr3[3]+'&vaccineTypeId='+arr3[6]+'&parentId='+arr3[7]+'&childId='+childIds+'\'">';
									htmls += '<span class="am-inline-block am-align-left am-margin-0 iconb">'+arr3[2]+'</span>';
										htmls += '<b class="font15 am-inline-block am-align-left am-margin-0 am-padding-left-xs w60 textleft">';
											htmls += '<span>';
											htmls += '<i>'+arr3[2]+'</i>';
											if(arr3[5] == 0){
												htmls += '<i>(免费)</i>';
											}else if(arr3[5] == 1){
												htmls += '<i>(自费)</i>';
											}
											htmls += '</span>';
											htmls += '<p class="colorb6bcce font13 twospaces">第'+arr3[1]+'剂/共'+data.obj[0].totalAgent+'剂</p>';
										htmls += '</b>';
										htmls += '<span class="am-inline-block font12 am-align-right am-margin-sm fontw600">';
											htmls+= '<input class="none idss" value="'+arr3[3]+'">';
											htmls += '<i class="am-icon-angle-right am-margin-right-xs text-6333AD am-icon-sm font15" style="color:#A8A5A1"></i>';
										htmls += '</span>';
								htmls += '</div>';
							htmls += '</div>';
							$('.vaccinename').append(htmls);
		   				}
			   		}else{
			   			var htmls = "";
			   			htmls += '<div class="zjyy_div"><img style="height:150px" src="../img/no.jpg"></div>';
			   			$('.vaccinename').html(htmls);
			   			$('.ckxgym').addClass('none');
			   		}
				}else{console.log("数据获取失败!")}
			}
		});
	}
	/*年龄事件*/
	$('body').on('click','.agePeriod>li',function(){
		$('.xgymxq').html("");
		$('.vaccinename').html("");
		var age = $(this).text();
		$(this).addClass('actives').siblings().removeClass('actives');
		ym.ajax({
			url:'/vaccine/queryVaccineInoculationPlan',
			param:{
					age:age,
					childBirthday:childBirthday,
				},
			success: function (data) {
		   	if(data.res == 1){
		   		if(data.obj.length > 0){
		   			$('.xgymxq').html("");
		   			$('.ckxgym').removeClass('none');
			   		for(var i=0;i<data.obj.length;i++){
			   			var arr =[];
			   			var arr2 = [];
			   			var arr3 = [];
			   			var zhi = data.obj[0].vaccineTypeName.indexOf(',');
			   			if(zhi == -1){
			   				data.obj[i].vaccineTypeName  = data.obj[i].vaccineTypeName+",";
			   			}
			   			arr = data.obj[i].vaccineTypeName.split('/');
			   		}
			   		arr2 = data.obj[0].vaccineTypeName.split(',');
			   		arr4 =[];
		   			for(var j=0;j<arr2.length;j++){
		   				var htmls = "";
		   				arr3 = arr2[j].split("/");
		   				if(arr3[2] != undefined){
		   					arr4.push(arr3[3]);
			   				htmls += '<div class="am-margin-top-sm zjyy_div am-padding-sm borbottoms">';
							    htmls += '<div class="am-block removefloat advice" onclick="window.location.href=\'vaccineXQ.html?vaccineId='+arr3[3]+'&vaccineTypeId='+arr3[6]+'\'">';
									htmls += '<span class="am-inline-block am-align-left am-margin-0 iconb">'+arr3[2]+'</span>';
										htmls += '<b class="font15 am-inline-block am-align-left am-margin-0 am-padding-left-xs w60 textleft">';
											htmls += '<span>';
											htmls += '<i>'+arr3[2]+'</i>';
											if(arr3[5] == 0){
												htmls += '<i>(免费)</i>';
											}else if(arr3[5] == 1){
												htmls += '<i>(自费)</i>';
											}
											htmls += '</span>';
											htmls += '<p class="colorb6bcce font13 twospaces">第'+arr3[1]+'剂/共'+data.obj[0].totalAgent+'剂</p>';
										htmls += '</b>';
										htmls += '<span class="am-inline-block font12 am-align-right am-margin-sm fontw600">';
											htmls+= '<input class="none idss" value="'+arr3[3]+'">';
											htmls += '<i class="am-icon-angle-right am-margin-right-xs text-6333AD am-icon-sm font15" style="color:#A8A5A1"></i>';
										htmls += '</span>';
								htmls += '</div>';
							htmls += '</div>';
							$('.vaccinename').append(htmls);
		   				}
		   				
	   				}
		   		}else{
		   			var htmls = "";
		   			htmls += '<div class="zjyy_div"><img style="height:150px" src="../img/no.jpg"></div>';
		   			$('.ckxgym').addClass('none');
					$('.vaccinename').append(htmls);
		   		}
				
		   		
		   	}else{console.log("数据获取失败!")}
		}
		});
	})
	/*查看相关疫苗*/
	$('body').on('click','.ckxgym',function(){
		console.log(arr4);
		var ht = $('.xgymxq').html();
		if(ht == ""){
			ym.ajax({
				url:'/vaccine/queryVaccineRelevanceDetail',
				param:{ vaccines:arr4},
				success:function(data){
					console.log(data);
					if(data.res ==1){
						var html = "";
						if(data.obj.length > 0){
							for(var i=0;i<data.obj.length;i++){
								html += '<div class="am-margin-top-sm zjyy_div am-padding-sm borbottoms">';
								html += '<div class="am-block removefloat advice advices" onclick="window.location.href=\'vaccineXQ.html?vaccineId='+data.obj[i].vaccineId+'&vaccineTypeId='+data.obj[i].vaccineTypeId+'\'">';
								html += '<span class="am-inline-block am-align-left am-margin-0 iconb">'+data.obj[i].vaccineTypeName+'</span>';
								html += '<b class="font15 am-inline-block am-align-left am-margin-0 am-padding-left-xs w60 textleft">';
								html += '<span>';
								html += '<i>'+data.obj[i].vaccineTypeName+'</i>';
								html += '</span>';
								html += '</b>';
								html += '<span class="am-inline-block font12 am-align-right am-margin-sm fontw600">';
								html += '<i class="am-icon-angle-right am-margin-right-xs text-6333AD am-icon-sm font15" style="color:#A8A5A1"></i>';
								html += '</span>';
								html += '</div>';
								html += '</div>';
							}
							$('.xgymxq').append(html);
						}else{
							html += '<div class="zjyy_div"><img style="height:150px" src="../img/no.jpg"></div>';
							$('.xgymxq').append(html);
						}
						
					}else{console.log("数据获取失败！")}
				}
			});
		}
	})
})
